package com.monkeyk.sos.web.controller;

import java.io.IOException;

import javax.servlet.http.HttpServletResponse;

import com.fasterxml.jackson.core.JsonEncoding;
import com.fasterxml.jackson.core.JsonFactory;
import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.databind.ObjectMapper;



public class BaseController {

	protected void writeJSON(HttpServletResponse response, Object obj)  {
		response.setContentType("application/json;charset=utf-8");
		ObjectMapper mapper = new ObjectMapper();
		JsonFactory factory = mapper.getFactory();
		JsonGenerator responseJsonGenerator = null;
		try {
			responseJsonGenerator = factory.createGenerator(response.getOutputStream(), JsonEncoding.UTF8);
		} catch (IOException e) {
			e.printStackTrace();
		}
		try {
			responseJsonGenerator.writeObject(obj);
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
}
